package cn.iocoder.yudao.module.promotion.fod.mq;

import cn.hutool.extra.spring.SpringUtil;
import cn.iocoder.yudao.module.api.member.vip.message.VipUserExpiredMessage;
import cn.iocoder.yudao.module.promotion.fod.service.FirstOrderDiscountVipRechargeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 平台首单优惠 事件消费者
 *
 * @author 山野羡民
 */
@Component
@Slf4j
public class FirstOrderDiscountConsumer {

    @EventListener
    @Async // Spring Event 默认在 Producer 发送的线程，通过 @Async 实现异步
    public void onMessage(VipUserExpiredMessage message) {
        log.info("[fod][onMessage][会员过期事件({})]", message);
        SpringUtil.getBean(FirstOrderDiscountVipRechargeService.class).updateUnused(message.getUserId());
    }

}
